package wms.api.modules.menu.controller;

import wms.api.core.bean.LoginAnnot;
import wms.api.modules.menu.entity.MenuEntity;
import wms.api.modules.menu.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/menus")
public class MenuController {
	@Autowired
	private MenuService menuService;

	/**
	 * 查询菜单列表
	 * @param menuEntity
	 * @return
	 */
	@LoginAnnot
	@GetMapping
	public ResponseEntity list(MenuEntity menuEntity) {
		return ResponseEntity.ok(menuService.list(menuEntity));
	}

	/**
	 * 查询菜单详情
	 * @param menuId
	 * @return
	 */
	@GetMapping("/{menuId}")
	public ResponseEntity detail(@PathVariable String menuId) {
		return ResponseEntity.ok(menuService.detail(menuId));
	}

	/**
	 * 新增菜单
	 * @param menuEntity
	 * @return
	 */
	@PostMapping
	public ResponseEntity add(@RequestBody MenuEntity menuEntity) {
		return ResponseEntity.ok(menuService.add(menuEntity));
	}

	/**
	 * 编辑菜单
	 * @param menuId
	 * @param menuEntity
	 * @return
	 */
	@PutMapping("/{menuId}")
	public ResponseEntity update(@PathVariable String menuId, @RequestBody MenuEntity menuEntity) {
		menuEntity.setId(menuId);
		return ResponseEntity.ok(menuService.update(menuId, menuEntity));
	}

	/**
	 * 删除菜单
	 * @param menuId
	 * @return
	 */
	@DeleteMapping("/{menuId}")
	public ResponseEntity delete(@PathVariable String menuId) {
		return ResponseEntity.ok(menuService.delete(menuId));
	}
}
